var add, edit, setVal, reset, $formData = $('#formData');
require(['validator', 'select2'], function () {
    $('form').initForm();
    add = function (fn) {
        var reg = /^[A-Za-z0-9_]+$/;
        if(($("#mftInsideCode").val()) && !(reg.test($("#mftInsideCode").val()))){ 
        	$.messager.alert("提示", "故障闪码只能为数字或字母！", "info");
        	return false;
        }else{
        	var result = $.validator($formData);
        	if (result) {
        		$.ajaxExt({
        			url: "/reportServiceManual/uptCommMftCopaEntity.htm",
        			data: $formData.getValues()
        		}).done(function () {
        			fn && fn();
        		});
        	}
        }
    };


    setVal = function (corpId, mftTypeCode, mftDiscCode) {
        $.ajaxExt({
            url: "/reportServiceManual/getMftInfoList.htm",
            data: {
                'corpId': corpId,
                'mftTypeCode': mftTypeCode,
                'mftDiscCode': mftDiscCode
            }
        }).done(function (data) {
        	console.info(data[0]);
        	if(data && data.rows && data.rows.length > 0){
        		var ar = data.rows;
        		$formData.setValues(ar[0]);
        	}
        });
    };

    reset = function () {
        $formData.reset();
    };

});